package com.wyq.new_springboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wyq.new_springboot.entity.TLog;
import com.wyq.new_springboot.mapper.TLogMapper;
import com.wyq.new_springboot.service.ITLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Mr Wei
 * @since 2021-03-24
 */
@Service
public class TLogServiceImpl extends ServiceImpl<TLogMapper, TLog> implements ITLogService {

    @Autowired
    TLogMapper tLogMapper;

    /**
     * 插入日志
     * @param tLog
     */
    @Override
    public void insert(TLog tLog) {
        tLogMapper.insert(tLog);
    }

    /**
     *
     * @param count 条数
     * @param sortName 排序字段
     * @return
     */
    @Override
    public List<TLog> selectLimit(int count, String sortName) {
        QueryWrapper<TLog> queryWrapper =new QueryWrapper<TLog>();
        queryWrapper
                .notIn("id",-1)//查询id不为-1的，也就是查询全部
                .orderByDesc(sortName);//按照时间排序
        Page<TLog> page=new Page<TLog>(1,count);//查询前5条
        return tLogMapper.selectPage(page, queryWrapper).getRecords();
    }
}
